<template>
    <div style="width: 100%;height: 100%;position: relative">
        <Button type="default" style=" position: absolute;top: 7px;right: 25px;z-index: 1;" v-if="!hiddenError"
                @click="toCheck">重新查验
        </Button>
        <Spin size="large" fix v-if="Loading"></Spin>
        <Form :label-width="180" ref="formValidate" :model="formValidate" id="form"
              :rules="ruleValidate">
            <div class="alert alert-warning" v-if="!hiddenError">事中查验异常，请重新查验再进行审批操作。</div>
            <div class="alert alert-danger" v-for="(i ,index) in interimCheckList" :key="index">{{i.message}}</div>
            <div v-if="isCheck">
                <div class="alert alert-info" v-if="alertType=='1'||alertType=='0'">{{alertMessage}}</div>
                <div class="alert alert-success" v-else-if="alertType=='2'">{{alertMessage}}</div>
                <div class="alert alert-warning" v-else-if="alertType=='3'">{{alertMessage}}</div>
                <div class="alert alert-danger" v-else-if="alertType=='4'">{{alertMessage}}</div>
            </div>
            <table>
                <tr>
                    <td>
                        <Form-item label="办理人:" prop="opusername">
                            <Input v-model="formValidate.opusername" placeholder=""
                                   style="width: 300px" disabled="disabled"/>
                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="办理时间:" prop="optime">
                            <DatePicker type="date" v-model="formValidate.optime"
                                        style="width: 300px" disabled="disabled"  :editable="false"></DatePicker>
                        </Form-item>
                    </td>
                </tr>

                <tr>
                    <td>
                        <Form-item label="退回原因:" prop="tpbl0006">
                            <c-dict-select v-model="formValidate.tpbl0006" dictCode="reject_reason" :width="300"
                                           showKeys="04,05,06,999"/>
                        </Form-item>
                    </td>
                    <td>
                        <Form-item label="终止原因:" prop="tpbl0007">
                            <c-dict-select v-model="formValidate.tpbl0007" dictCode="terminate_reason" :width="300"
                                           showKeys="04,05,06,999"/>
                        </Form-item>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <Form-item label="办理意见说明:" prop="opmemo">
                            <c-text-area v-model="formValidate.opmemo" :max-length="100" :row="3" width="890"
                                         placeholder="请输入办理意见说明"/>
                        </Form-item>
                    </td>

                </tr>
            </table>
        </Form>
    </div>
</template>

<script>
    /**
     * 乡镇街道初审
     */
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import {postAction} from '@/api/request'

    export default {
        components: {},
        mixins: [CommonMixin],
        name: "handle04",
        data() {
            return {
                Loading: false,
                familyInfo: {},
                formValidate: {
                    opusername: "",
                },
                isCheck: false,
                interimCheckList: [],
                hiddenError: false,
                disabled: true,
                information: "",
                alertType: "",
                alertMessage: "",
                ruleValidate: {
                    opusername: [
                        {required: true, message: '办理人不能为空!', trigger: 'blur',}
                    ],
                    optime: [
                        {required: true, message: '办理时间不能为空!', trigger: 'blur', type: "date"}
                    ],
                    opmemo: [
                        {required: true, message: '办理意见说明不能为空!', trigger: 'blur',}
                    ],
                    tpbl0006: [
                        {required: false, message: '退回原因不能为空!', trigger: 'change',}
                    ],
                    tpbl0007: [
                        {required: false, message: '终止原因不能为空!', trigger: 'change',}
                    ]
                },
                userInfor: {},
                ss12001Id: "",
                canGoOn: false,//是否可以继续审批
            }
        },
        methods: {
            check(name) {
                this.setRequired(name, this.ruleValidate);
                var infor = false;
                this.$refs['formValidate'].validate((valid) => {
                    if (valid) {
                        infor = this.formValidate;
                    }
                })
                return infor;
            },
            //审批事中校验
            // interimCheck(resolve) {
            //     postAction("/api/ac/subsistence/ss12001Service/interimCheck", {
            //         ss12001Id: this.ss12001Id
            //     }).then((res) => {
            //         if (res.data.errcode == 0) {
            //             this.hiddenError = true;
            //             if (res.data.data.length == 0) {
            //                 this.checkStatus(resolve);
            //             } else {
            //                 this.interimCheckList = res.data.data;
            //                 resolve(1);
            //             }
            //         } else {
            //             resolve(1);
            //         }
            //     })
            // },
            //查看核对报告状态
            checkStatus(resolve) {
                postAction("/api/ac/subsistence/ss12001Service/checkStatus", {
                    ss12001Id: this.ss12001Id
                }).then((res) => {
                    if (res.data.errcode == 0) {
                        this.isCheck = res.data.data.isCheck;
                        this.alertType = res.data.data.alertType;
                        this.alertMessage = res.data.data.alertMessage;
                        this.formValidate.ssca0072 = res.data.data.ssca0072;
                        this.canGoOn = true;
                    }
                }).finally(() => {
                    resolve(1)

                })
            },

            toCheck() {
                this.isCheck = false;
                this.interimCheckList.length = 0;
                this.hiddenError = true;
                this.$emit('setButtonHidden', false);
                var ss12001Id = this.$parent.$parent.$parent.$parent.$parent.ss12001Id;
                this.ss12001Id = ss12001Id;
                var that = this;
                that.Loading = true;
                Promise.all([
                    new Promise((resolve, reject) => {
                        this.getUserInfor(resolve);
                    }),
                    new Promise((resolve, reject) => {
                        this.getServerTime(resolve);
                    }),
                    new Promise((resolve, reject) => {
                        this.checkStatus(resolve);
                    }),
                ]).then(res => {
                    var date = this.DateFormat(res[1], 'YYYY-MM-DD');
                    this.$set(this.formValidate, "opusername", res[0].name);
                    this.$set(this.formValidate, "optime", date);
                    that.Loading = false;
                    // if (!this.canGoOn) {
                    //     this.$emit('lockAllButton', true);
                    // } else {
                    //     this.$emit('lockAllButton', false);
                    // }
                    this.$emit('setButtonHidden', false);
                })
            }
        },
        created() {
            this.toCheck();
        }
    }
</script>

<style scoped src="../../../common/css/rightTip.css">
    #refresh {

    }

</style>
